import Mock from 'mockjs'
import { result, getNowTime, mockPageRes, qsparse } from '../util'
export const mockCustomerInfoList = (params) => result(() => {
  const list = []
  const c1 = { customerName: '深圳动力有限公司', customerCode: 'C000001', mobilephone: '1381888375', channel: 1, address: '湖南省长沙市', level: 'A', chargePerson: '王磊', creater: '刘佳丽', createTime: getNowTime(), updateTime: getNowTime() }
  const c2 = { customerName: '上海财东科技有限公司', customerCode: 'C000002', mobilephone: '1581982371', channel: 2, address: '北京市朝阳区', level: 'B', chargePerson: '李利', creater: '王丽红', createTime: getNowTime(), updateTime: getNowTime() }
  const c3 = { customerName: '上海财东科技有限公司2', customerCode: 'C000003', mobilephone: '1881888372', channel: 1, address: '北京市朝阳区', level: 'C', chargePerson: '李利', creater: '王丽红', createTime: getNowTime(), updateTime: getNowTime() }
  list.push(c1, c2, c3)
  const channel = [1, 2]
  const level = ['A', 'B', 'C']
  const info = Mock.mock({
    'list|10': [
      {
        'customerName': '@city()@ctitle(3)有限公司',
        'customerCode': /C[0-9]{7}/,
        'mobilephone': /1[3-8]{1}[0-9]{9}/,
        'channel|1': channel,
        'level|1': level,
        'chargePerson': '@cname',
        'creater': '@cname',
        'address': '@county(true)',
        'createTime': '@datetime',
        'updateTime': '@now'
      }
    ]
  })
  return mockPageRes(params, info.list)
})

export const mockContactsList = (customerCode) => result(() => {
  const list = []
  if (customerCode === 'C000001') {
    const c1 = { customerCode: 'C000001', customerName: '深圳动力有限公司', contactsName: '王兴', 'gender': 1, mobilephone: '13012991885', email: '9998343@qq.com', primaryContact: 1, post: '采购员组长', address: '深圳龙华区100号', remark: '采购主要负责人热情而且而且为人而且为人却而我惹' }
    const c2 = { customerCode: 'C000001', customerName: '深圳动力有限公司', contactsName: '刘丽', 'gender': 0, mobilephone: '18912971801', email: 'liuli@163.com', primaryContact: 0, post: '采购员', address: '深圳福田区98号', remark: '采购助理' }
    list.push(c1, c2)
  }
  return list
})

export const mockChannelList = () => result(() => {
  const list = []
  const c1 = { label: '电话', value: 1 }
  const c2 = { label: '网络', value: 2 }
  const c3 = { label: '展会', value: 3 }
  const c4 = { label: '推荐', value: 4 }
  list.push(c1, c2, c3, c4)
  return list
})


export default {
  'post|/api/getCustomerInfoList': (option) => {
    const params = qsparse(option.body)
    return mockCustomerInfoList(params)
  },
  'post|/api/getContactsList': (option) => {
    const params = qsparse(option.body)
    return mockContactsList(params)
  },
  'post|/api/getChannelList': mockChannelList
}
